package com.pagepub.core.tag.validator;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class ValidateLength extends FormValidateBasic {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8081591062636876782L;

	/**
	 * @param args
	 */

	@Override
	public int doStartTag() throws JspException {
		// TODO 自动生成方法存根

		StringBuffer string = new StringBuffer();
		string.append(validatelength());

		JspWriter out = (JspWriter) this.pageContext.getOut();
		try {
			out.print(validatelength());
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return 1;
	}

	public StringBuffer validatelength() {
		StringBuffer str = new StringBuffer();
		// this.doStartTag();
		str.append("<script language=\"javascript\">");
		str
				.append("function ValidateLength(realvalue,minlen,maxlen,realname,spanname){");
		str.append("var flag=0;");
		str.append(" var truevalue=cTrim(realvalue,0);");
		str.append("if(truevalue!=\"\"){");
		str.append("			if(truevalue.length<minlen)");
		str.append("			{");
		str.append("				message=\"对不起,\"+realname+\"长度不能小于\"+minlen+\"!\";");
		str.append("				imgurl=\"<img src=\\\"" + this.getWrongimage()
				+ "\\\"/>\";");
		str.append("				flag=1;");
		str.append("			} ");
		str.append("			else if(truevalue.length>maxlen)");
		str.append("			{");
		str.append("				message=\"对不起,\"+realname+\"长度不能大于\"+maxlen+\"!\";	");
		str.append("				imgurl=\"<img src=\\\"" + this.getWrongimage()
				+ "\\\"/>\";");
		str.append("				flag=1;");
		str.append("			}");
		str.append("             if(flag==1) {");
		str.append(this.display());
		str.append("return false ;");
		str.append("            } else{");
		str.append(this.displayempty());
		str.append("return true ;}");
		str.append("			");
		str.append("		}");
		str.append("}");
		str.append("</script>");
		str.append(this.cTrim());
		return str;
	}
}
